package com.wdh.kjs.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.wdh.kjs.R;
import com.wdh.kjs.http.Httpurl;
import com.wdh.kjs.model.JsonModel;
import com.wdh.kjs.util.DateUtilChange;
import com.wdh.kjs.util.ToastUtils;

import java.util.HashMap;

/**
 * Created by CQH on 2016/4/21.
 */
public class NoticeDetailsActivity extends BaseTopActivity implements View.OnClickListener {
    private Button exitLogin;
    private HashMap<String, String> maps = new HashMap<String, String>();
    private Bundle bundle;
    private Intent intent;
    private TextView tv_notice_detail_title;
    private TextView tv_notice_detail_time;
    private String userReceiveMessageId;
    private JsonModel jsonModel;
    private TextView tv_notice_detail_context;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_notice_detail);
        userReceiveMessageId = getIntent().getStringExtra("userReceiveMessageId");
        initTopBar("公告详情");
        initview();
        intweb();
    }

    private void intweb() {
        RequestParams params = new RequestParams();
        params.addBodyParameter("userReceiveMessageId", userReceiveMessageId);

        HttpUtils http = new HttpUtils();
        http.send(HttpRequest.HttpMethod.POST, Httpurl.URL_NOTICE_ACTIVITY_DETAIL, params, new RequestCallBack<String>() {

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {


                Gson gson = new Gson();
                jsonModel = gson.fromJson(responseInfo.result, JsonModel.class);
                if (jsonModel.success) {
                    String time = DateUtilChange.timestamp2String(jsonModel.getMessagedetail().get(0).getCreatedTxStamp(),DateUtilChange.DEFAULT_SECOND_FORMAT);
                    tv_notice_detail_title.setText(jsonModel.getMessagedetail().get(0).getUserMessageTitle());
                    tv_notice_detail_time.setText(time);
                    tv_notice_detail_context.setText(jsonModel.getMessagedetail().get(0).getUserMessageContent());
                }


            }

            @Override
            public void onFailure(HttpException error, String msg) {

                ToastUtils.showShort(NoticeDetailsActivity.this, "网络异常！");
            }
        });

    }

    private void initview() {

        tv_notice_detail_title=(TextView)findViewById(R.id.tv_notice_detail_title);
        tv_notice_detail_time=(TextView)findViewById(R.id.tv_notice_detail_time);
        tv_notice_detail_context = (TextView) findViewById(R.id.tv_notice_detail_context);


    }

    public void onClick(View v) {
    }
}
